package com.easy.service.impl;

import com.easy.annotation.LogMethod;
import com.easy.bean.User;
import com.easy.mapper.UserMapper;
import com.easy.service.RegisterService;
import com.easy.util.PasswordUtil;
import com.easy.util.SYS;
import com.easy.util.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegisterServiceImpl implements RegisterService {

    @Autowired
    UserMapper userMapper;

    @Override
    @LogMethod(serviceName = "用户注册", recordParam = true, recordReturn = true)
    public String register(User user) {
        //密码加密写入
        String encryption = PasswordUtil.getEncryption(user.getPassword());
        user.setPassword(encryption);
        userMapper.add(user);
        //获取用户id,token
        Integer id = user.getId();
        String token = TokenUtil.getToken(id, SYS.REGULAR_USER);
        return token;
    }
}
